﻿using MediatR;
using T_Person.BaseRep.Interface;
using T_Person.Read.APi.Applaction.Command;
using T_Person.Read.APi.Dto;

namespace T_Person.Read.APi.Applaction.CommandHandlers
{
    public class EmployeeSearchByDidCommandHandler : IRequestHandler<EmployeeSearchByDidCommand, List<EmployeeNameDto>>
    {
        private readonly IEmployeeRep employeeRep;

        public EmployeeSearchByDidCommandHandler(IEmployeeRep employeeRep)
        {
            this.employeeRep = employeeRep;
        }
        /// <summary>
        /// 获取部门相关的下拉列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<List<EmployeeNameDto>> Handle(EmployeeSearchByDidCommand request, CancellationToken cancellationToken)
        {
            var list = await employeeRep.GetvaluesByResult(x => x.DepartId.Equals(request.id)&&x.IsDel.Equals(false)&&x.EmployeeStyle.Equals(4));
            var lists=new List<EmployeeNameDto>();
            foreach (var item in list)
            {
                lists.Add(new EmployeeNameDto
                {
                    id = item.Eid,
                    Name = item.Ename,
                });
            }
            return lists;
        }
    }
}
